package com.action.basic;

import java.util.List;

import com.action.common.WEB;
import com.opensymphony.xwork2.ActionSupport;
import com.pojo.basic.DEPT;
import com.service.basic.IDEPTService;
import com.util.ActionLog;
import com.util.GTC;

public class DEPTAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private IDEPTService deptService;
	private String datas;
	
	//setter getter
	
	public void setDeptService(IDEPTService deptService) {
		this.deptService = deptService;
	}
	
	public String getDatas() {
		return datas;
	}

	public void setDatas(String datas) {
		this.datas = datas;
	}

	//action method
	public String findAllDEPT(){
		ActionLog.info(this.getClass(),"["+WEB.getClassName(this.getClass())+"]:【加載所有部門资料】");
		this.allDeptFormatExtArray(deptService.findAllDEPT());
		return SUCCESS;
	}
	
	public void allDeptFormatExtArray(List<DEPT> lists){
		ActionLog.info(this.getClass(),"["+WEB.getClassName(this.getClass())+"]:【部門對象轉換為JS字符串形式顯示在頁面】");
		StringBuffer sb = new StringBuffer();
		sb.append("[");
		for(DEPT dept : lists){
			sb.append("['"+dept.getDEP()+"','"+GTC.nullEmpty(dept.getNAME())+"','"+GTC.nullEmpty(dept.getUP())+"','"+GTC.nullEmpty(dept.getENG_NAME())+"','"+GTC.nullEmpty(dept.getSTOP_DD())+"','"+GTC.nullEmpty(dept.getGROUP_ID())+"','"+GTC.nullEmpty(dept.getUSR())+"','"+GTC.nullEmpty(dept.getSYS_DATE())+"','"+GTC.nullEmpty(dept.getSPC_NO())+"'],");
		}
		this.setDatas(sb.toString().substring(0, sb.toString().length()-1)+"]");
	}
}
